package com.polaris.live.ui.message.fragment

import android.os.Bundle
import android.view.View
import androidx.core.os.bundleOf
import com.polaris.live.R
import com.polaris.live.common.mvvm.base2.BaseVbFragment
import com.polaris.live.constant.LiveConst
import com.polaris.live.databinding.FragmentMessageStrangerBinding
import com.polaris.live.im.sfs.COMMAND_STRANGER_MESSAGE
import com.polaris.live.utils.fragment.attachFragment
import com.polaris.live.viewmodel.message.MainMessageViewModel

/**
 * MessageStrangerFragment
 *
 * @author Created by lucas on 2023/10/27 13:53
 */
class MessageStrangerFragment :
    BaseVbFragment<MainMessageViewModel, FragmentMessageStrangerBinding>() {

    private var onLeftClientListener: View.OnClickListener? = null

    private val mNestedPage by lazy {
        arguments?.getBoolean("nestedPage") ?: false
    }

    private val mNeedClickAvatar by lazy { arguments?.getBoolean(LiveConst.Params.NEED_CLICK_AVATAR, true) ?: true }

    private val mFragment by lazy {
        childFragmentManager.attachFragment(R.id.fl_fragment) {
            MessageSessionFragment().apply {
                arguments = bundleOf(
                    "sessionCommand" to COMMAND_STRANGER_MESSAGE,
                    "nestedPage" to mNestedPage,
                    LiveConst.Params.NEED_CLICK_AVATAR to mNeedClickAvatar,
                )
            }
        }
    }

    override fun initView(savedInstanceState: Bundle?) {

        mBinding.bvTitle.setOnLeftClientListener {
            onLeftClientListener?.onClick(it)
        }

        mBinding.bvTitle.setOnRightClientListener {
            mFragment.clearStrangerUnreadCount()
        }

        mFragment
    }

    fun setOnLeftClientListener(listener: View.OnClickListener) {
        this.onLeftClientListener = listener
    }
}